#include <sys/ioctl.h>
#include <linux/device.h>
#include <linux/dmaengine.h>

#define ADCDMA_IOCTL_MAGIC 'D'
/*参数分别为：魔数、命令编号、传参类型*/
#define SET_DMA_BUF_NUM _IOWR(ADCDMA_IOCTL_MAGIC, 0, unsigned int) 
#define DMA_STREAM_ON _IO(ADCDMA_IOCTL_MAGIC, 1)
#define DMA_UPDATE_TAIL _IO(ADCDMA_IOCTL_MAGIC, 2)



#define MAX_DMA_BUF_CNT 128
#define DMA_BUF_SIZE	8192//考虑缓存页与DMA总线对齐，使用了get_order()接口，故值必须为2的幂
#define CLASS_NAME "adcdma"
#define DEVICE_NAME "ada"





struct dma_map_info {
    unsigned long offset;
    size_t size;
};

//设备信息结构体，用于注册字符设备
typedef struct ADC2DMA_DEVICE_MESG
{
	dev_t devid;
	struct cdev cdev;
	struct class* class;
	struct  device* device;
}ADC2DMA_DEVICE_MESG;

typedef struct ADC2DMA_DRIVER_MESG
{
    struct device_node* nd;//设备树节点
    struct  device* dev;//设备
    struct dma_chan* dma_ch;//DMA通道
    struct dma_async_tx_descriptor* desc;//DMA传输描述符
    dma_cookie_t cookie;//DMA调试信息
    char* dma_buf[MAX_DMA_BUF_CNT];//指向DMA缓冲区虚拟地址的指针,
    dma_addr_t dma_dsts[MAX_DMA_BUF_CNT];//DMA传输目的地址
    unsigned int dma_buf_num;
    unsigned int head;//环形缓冲区头（考虑使用原子变量）
    unsigned int tail;//环形缓冲区尾
}ADC2DMA_DRIVER_MESG;


